/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lab.distribuidos;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author A-SOFT03
 */
public class Principal extends javax.swing.JFrame {

    private Conexion conexion;
    private String[] cabeceraMensajes;
    String idMensaje;

    /**
     * Creates new form Principal
     */
    public Principal(Conexion conexion) {
        
        initComponents();
        this.conexion = conexion;
        
        conexion.setConsola(this.txtAreaConsola);
        
        conexion.enviarComando("STAT");
        conexion.listarMensajes();

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      
    }

 

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelConsola = new javax.swing.JScrollPane();
        txtAreaConsola = new javax.swing.JTextArea();
        lblConsola = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        menuCorreo = new javax.swing.JMenu();
        menuModo = new javax.swing.JMenu();
        radioModoCG = new javax.swing.JRadioButtonMenuItem();
        radioModoCE = new javax.swing.JRadioButtonMenuItem();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        txtAreaConsola.setColumns(20);
        txtAreaConsola.setRows(5);
        panelConsola.setViewportView(txtAreaConsola);

        lblConsola.setFont(new java.awt.Font("Tahoma", 0, 14));
        lblConsola.setText("Consola");

        menuCorreo.setText("Correo");
        menuBar.add(menuCorreo);

        menuModo.setText("Modo");

        radioModoCG.setSelected(true);
        radioModoCG.setText("Cargar y Eliminar");
        radioModoCG.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioModoCGActionPerformed(evt);
            }
        });
        menuModo.add(radioModoCG);

        radioModoCE.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioModoCEActionPerformed(evt);
            }
        });
        menuModo.add(radioModoCE);

        menuBar.add(menuModo);

        jMenu1.setText("Consola");

        jMenuItem1.setText("Limpiar");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        menuBar.add(jMenu1);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panelConsola, javax.swing.GroupLayout.DEFAULT_SIZE, 555, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblConsola)
                        .addGap(0, 507, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(227, Short.MAX_VALUE)
                .addComponent(lblConsola)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelConsola, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void radioModoCGActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioModoCGActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_radioModoCGActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
            conexion.limpiarConsola();
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void radioModoCEActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioModoCEActionPerformed
            radioModoCG.setSelected(false);
            conexion.cambiarModo(conexion.CARGAR_ELIMINAR);
    }//GEN-LAST:event_radioModoCEActionPerformed

    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JLabel lblConsola;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenu menuCorreo;
    private javax.swing.JMenu menuModo;
    private javax.swing.JScrollPane panelConsola;
    private javax.swing.JRadioButtonMenuItem radioModoCE;
    private javax.swing.JRadioButtonMenuItem radioModoCG;
    private javax.swing.JTextArea txtAreaConsola;
    // End of variables declaration//GEN-END:variables
}
